約 4,333,243 件
https://w.atwiki.jp/mypad/pages/23.html
openFrameworksを使っているとopenGLの知識が必要になってくる ofxARToolkitPlusという拡張現実の描画をしているのもOPENGL。 どうも座標があわないなと思っていたら ただし、OpenGLでは、座標の原点(0,0)は左下です。 とのこと。y座標が上下逆で、デカルト座標系なんですね。 http //sky.geocities.jp/freakish_osprey/opengl/opengl_viewport.htm
https://w.atwiki.jp/sabupot/pages/16.html
OpenGLに関するリンク集です。 GLUTによる「手抜き」OpenGL入門 ↑情報量が多いです。OpenGLのインストール方法も詳しく書いてあります。 OpenGL Programin ↑よく見てないので分かりません。
https://w.atwiki.jp/june1st/pages/13.html
C++BuilderでVCLと共存してGLUTを使う ココのサンプルを参考に プロジェクトに追加で glut32.libと OpenGLのプログラム.c() ← glutInit( _argc, _argv)、glutCreateWindow("sample")、main() → (例えば)GLmain を追加 Project1.cppに USELIB("glut32.libのパス"); USEUNIT("OpenGLのプログラム.c"); Unit1.cpp側で extern "C" int GLmain(void); 外部関数として"OpenGLのプログラム.c"に書かれた関数を呼び出す グローバル変数も外部呼出ししてVCLでいじればおk UbuntuでGLUTを使う とりあえずsynapticでGLUTをインストール(GLUT3〜? gccのオプションに-lglut -lGLU -lGLをつける
https://w.atwiki.jp/ookubo/pages/19.html
ゲームテクニック ゲームに関する情報 OpenGL の描画処理を高速化についてのkeyWard. ・ディスプレイリスト ・頂点配列 ・VBO = Vertex Buffer Object ・カリング カリング- OpenGLビュークラスを作る- OpenGL サンプル --
https://w.atwiki.jp/bambooflow/pages/282.html
グローシェーディング - 頂点シェーダでのライティング 注意:ここでかかれている内容は、本来のグローシェーディングという用語に対して使い方が間違っているかもしれませんが、ここでは、頂点シェーダでのライティングをグローシェーディングと呼ぶことにします。 グローシェーディング - 頂点シェーダでのライティンググローシェーディング(gouraud shading)について 照明モデルの計算 GLSL実装 ダウンロード サンプルは白の光源が物体のまわりをぐるぐる回ります。 環境 OpenGL 3.3 GLUT(freeglut) - 2.6.0 GLEW - 1.5.7 GLM - 0.9.0.6 グローシェーディング(gouraud shading)について グローシェーディングは、頂点ごとに光源計算を行う陰影付け手法の1つ。 gouraud氏が1971年に公開した技術。 計算処理は主にバーテックスシェーダ側で行うことになります。 面を構成する頂点の法線を用い頂点の明るさを計算 各点の明るさを頂点の明るさの線形補間によって求める 線形補間を用いることで、フラットシェーディングと比較してスムースになります。 グローシェーディングでは、頂点ごとに計算すればよいので、計算量は比較的少ないが、光源が頂点近くにあると光沢の不自然さが残ります。 その光沢の不自然さを改善したものが、Phongシェーディングになります。 照明モデルの計算 Diffuse Reflection(拡散反射) Lambert(ランバート)反射。 Id = Ii Kd cos(A) Iiは、元の光の強さ Aは入射角(0~90度)、法線ベクトルとの角度差 Kdは光の入射定数 ランバートの余弦則 「その点の明るさは面の向き(法線ベクトル)と光の入射方向の角度差θのcosθに比例する」 式は、次のように変換できます。 Id = Ii Kd (L.N) Nは、物体表面の法線ベクトル Lは、面上の点光源からの光とのベクトル Ambient Light(環境光) I = Ia Ka Iaは環境光の強さ Kaは環境反射係数 Specular Reflection(鏡面反射) I = Ia Ka + Ii [ Kd(L.N) + Ks cos(B)^n] つまり、 I = Ia Ka + Ii [ Kd(L.N) + Ks(R.V)^n ] Bは、ベクトルVと反射ベクトルRの間の角度 Rは、反射ベクトル Vは、視線ベクトル Lは、光源ベクトル nは鏡面反射指数 反射ベクトルRは次の方程式から計算されます. R = 2N(N.L)-L ただし、Rの計算はコストが高いため、ハーフベクトルHで代用することが可能。 H = (L + V) / 2 ハーフベクトルを使うと、 I = Ia Ka + Ii [ Kd(L.N) + Ks(N.H)^n ] ちなみに、ハーフベクトルを用いた計算は物理的に正しくない。あくまでも計算コストを下げるための近似式。 反射ベクトル ハーフベクトル GLSL実装 視点座標空間で計算。 頂点シェーダ #version 330 struct MaterialParam { vec4 ambient; vec4 diffuse; vec4 specular; float shininess; }; uniform vec3 u_lightPos; uniform MaterialParam u_lightMaterial; uniform MaterialParam u_material; uniform mat4 u_modelMatrix; // モデル・マトリックス uniform mat4 u_viewMatrix; // ビュー・マトリックス uniform mat4 u_projectionMatrix; // 射影・マトリックス in vec3 a_position; in vec3 a_normal; out vec4 v_color; void main(void) { mat4 modelViewMatrix = u_viewMatrix * u_modelMatrix; vec3 lightVec = vec3(u_viewMatrix * vec4(u_lightPos.xyz,1.0)); mat3 n_mat = mat3( transpose( inverse(modelViewMatrix) ) ); // normal Matrix vec3 P = vec3(modelViewMatrix * vec4(a_position,1.0)); // Eye vector vec3 N = normalize(n_mat * a_normal); // normal direction vec3 L = normalize(lightVec - P); // light direction vec3 V = normalize(-P); // eye direction float nDotL = dot(N,L); float diffuseLight = max(nDotL,0.0); vec4 ambient = u_lightMaterial.ambient * u_material.ambient; vec4 diffuse = u_lightMaterial.diffuse * u_material.diffuse * diffuseLight; vec3 R = reflect(-L,N); // 反射ベクトルによるスペキュラー 2N(N.L)-L float nDotH = pow(max(dot(V,R),0.0), u_material.shininess); //vec3 H = normalize(L+V); // ハーフベクトルによるスペキュラー //float nDotH = pow(max(dot(N,H),0.0), u_material.shininess); if (nDotL 0.0) nDotH = 0.0; vec4 specular = u_lightMaterial.specular * u_material.specular * nDotH; v_color = ambient + diffuse + specular; gl_Position = u_projectionMatrix*modelViewMatrix*vec4(a_position.xyz, 1.0); } フラグメントシェーダ #version 330 in vec4 v_color; out vec4 fragColor; void main(void) { fragColor = v_color; } メモ1 次の計算で、viewMatrix×ModelMatrixを算出。 この計算は1つのモデルで共通で頂点ごとの計算は必要ないのでアプリケーション側でさせておくことも可能。大抵の参考書ではアプリケーション側で計算させていますが、ここではとりあえずシェーダ側で計算。 mat4 modelViewMatrix = u_viewMatrix * u_modelMatrix; メモ2 次の計算で法線ベクトルを視点座標空間に変換。 OpenGL2.x系でgl_NormalMatrixがn_matに当たる。 この計算もシェーダ側ではなくアプリケーション側でさせることも可能。 逆行列の計算は処理が大きいのでアプリケーション側で済ませておく方がよいかもしれません。 mat3 n_mat = mat3( transpose( inverse(modelViewMatrix) ) ); // normal Matrix vec3 N = normalize(n_mat * a_normal); // normal direction ダウンロード glsl_gouraud00.tgz
https://w.atwiki.jp/cappu/pages/37.html
OpenGL ESの勉強を始める ApiDemosのGLSurfaceViewを1クラスにまとめてみた。別スレッドからの更新やリサイズの再描画はなし。 public class Sample extends Activity { public static class MyView extends SurfaceView implements SurfaceHolder.Callback { public MyView(Context context) { super(context); SurfaceHolder mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceCreated(SurfaceHolder holder) { EGL10 mEgl = (EGL10) EGLContext.getEGL(); EGLDisplay mEglDisplay = mEgl .eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; mEgl.eglInitialize(mEglDisplay, version); EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; int[] configSpec = { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE }; mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config); EGLConfig mEglConfig = configs[0]; /* * Create an OpenGL ES context. This must be done only once, an * OpenGL context is a somewhat heavy object. */ EGLContext mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null); EGLSurface /* * Create an EGL surface we can render into. */ mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, holder, null); /* * Before we can issue GL commands, we need to make sure the context * is current and bound to a surface. */ mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); GL10 gl = (GL10) mEglContext.getGL(); gl.glViewport(0, 0, getWidth(), getHeight()); /* * Set our projection matrix. This doesn t have to be done each time * we draw, but usually a new projection needs to be set when the * viewport is resized. */ float ratio = (float) getWidth() / getHeight(); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); /* * Usually, the first thing one might want to do is to clear the * screen. The most efficient way of doing this is to use glClear(). */ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); /* * Now we re ready to draw some 3D objects */ gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -3.0f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_COLOR_ARRAY); // --------- int one = 0x10000; int vertices[] = { -one, -one, -one, one, -one, -one, one, one, -one, -one, one, -one, -one, -one, one, one, -one, one, one, one, one, -one, one, one, }; int colors[] = { 0, 0, 0, one, one, 0, 0, one, one, one, 0, one, 0, one, 0, one, 0, 0, one, one, one, 0, one, one, one, one, one, one, 0, one, one, one, }; byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; IntBuffer mVertexBuffer; IntBuffer mColorBuffer; ByteBuffer mIndexBuffer; // Buffers to be passed to gl*Pointer() functions // must be direct, i.e., they must be placed on the // native heap where the garbage collector cannot // move them. // // Buffers with multi-byte datatypes (e.g., short, int, float) // must have their byte order set to native order ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4); vbb.order(ByteOrder.nativeOrder()); mVertexBuffer = vbb.asIntBuffer(); mVertexBuffer.put(vertices); mVertexBuffer.position(0); ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length * 4); cbb.order(ByteOrder.nativeOrder()); mColorBuffer = cbb.asIntBuffer(); mColorBuffer.put(colors); mColorBuffer.position(0); mIndexBuffer = ByteBuffer.allocateDirect(indices.length); mIndexBuffer.put(indices); mIndexBuffer.position(0); gl.glFrontFace(gl.GL_CW); gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer); gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer); gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer); mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); if (mEglSurface != null) { mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay, mEglSurface); mEglSurface = null; } if (mEglContext != null) { mEgl.eglDestroyContext(mEglDisplay, mEglContext); mEglContext = null; } if (mEglDisplay != null) { mEgl.eglTerminate(mEglDisplay); mEglDisplay = null; } } @Override public void surfaceDestroyed(SurfaceHolder holder) { } } private MyView mGLSurfaceView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGLSurfaceView = new MyView(this); setContentView(mGLSurfaceView); } @Override protected void onPause() { super.onPause(); } @Override protected void onResume() { super.onResume(); } }
https://w.atwiki.jp/dendenkeroro/pages/52.html
ARToolkitを実現するにはOpenGLも習得しておく必要があります。 各種要素となるプログラムソースを公開しておきます。 開発環境はARToolkitを参照してください。 プログラミングに関してはARToolkitでも紹介した書籍、 および下記HP「NaturalScience」様を参考にしております。 そちらではソースの解説があまりないので、必要に応じて補足、コメントなどしています。 ただし、読者の方々にはC言語に関する基礎知識があるものとして説明しております。 (c)NaturalScience VisualStudio2010ではどう設定するの? VisualStudio2010が公開されましたね。2008とは若干仕様が変わりましたので、それを紹介します。 まずGLUTのインストールですが、glut.hをどこに置くかが問題になります。アドレスは以下の通り。 C \Program Files\Microsoft Visual Studio 10.0\Vc\Include\gl\glut.h glフォルダはデフォルトで存在しないので、自分で作ってください。 また、2010ではプロジェクトでのプロパティ設定のみとなっているので、 「インクルードディレクトリ」と「ライブラリディレクトリ」は「プロジェクトのプロパティ」から設定してください。 「VC++ディレクトリ」という項目が2010では新設されておりますので。 とりあえずWindowを表示してみよう(2010/5/5 編集中) まずはOpenGLでウィンドウを表示してみましょう。 かといって真っ白画面だと味気ないので、格子状の地面も表示します。 +←ソースを表示するにはこちらをクリック #include ‹math.h› #include ‹fstream› #include ‹sstream› #include ‹iostream› #include ‹direct.h› #include ‹GL/glut.h› int WindowPositionX = 400; //生成するウィンドウ位置のX座標 int WindowPositionY = 200; //生成するウィンドウ位置のY座標 int WindowWidth = 640; //生成するウィンドウの幅 int WindowHeight = 480; //生成するウィンドウの高さ char WindowTitle[] = ロボット視点 ; //ウィンドウのタイトル double ViewPointX = 0.0;//視点X座標 double ViewPointY = -300.0;//視点Y座標 double ViewPointZ = 50.0;//視点Z座標 //---------------------------------------------------- // 関数プロトタイプ(後に呼び出す関数名と引数の宣言) //---------------------------------------------------- void Initialize(void); void Display(void); void Idle(); void Ground(void); //地面の描画Keyboard //---------------------------------------------------- // メイン関数 //---------------------------------------------------- int main(int argc, char *argv[]){ glutInit(&argc, argv);//環境の初期化 glutInitWindowPosition(WindowPositionX, WindowPositionY);//ウィンドウの位置の指定 glutInitWindowSize(WindowWidth, WindowHeight); //ウィンドウサイズの指定 glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);//ディスプレイモードの指定 glutCreateWindow(WindowTitle); //ウィンドウの作成 glutDisplayFunc(Display); //描画時に呼び出される関数を指定する(関数名:Display) glutIdleFunc(Idle); //プログラムアイドル状態時に呼び出される関数 Initialize(); //初期設定の関数を呼び出す glutMainLoop(); return 0; } //---------------------------------------------------- // 初期設定の関数 //---------------------------------------------------- void Initialize(void){ glClearColor(1.0, 1.0, 1.0, 1.0); //背景色 glEnable(GL_DEPTH_TEST);//デプスバッファを使用:glutInitDisplayMode() で GLUT_DEPTH を指定する } //---------------------------------------------------- // 描画の関数 //---------------------------------------------------- void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //バッファの消去 //透視変換行列の設定------------------------------ glMatrixMode(GL_PROJECTION);//行列モードの設定(GL_PROJECTION 透視変換行列の設定、GL_MODELVIEW:モデルビュー変換行列) glLoadIdentity();//行列の初期化 gluPerspective(30.0, (double)WindowWidth/(double)WindowHeight, 0.1, 1000.0); //透視投影法の視体積gluPerspactive(th, w/h, near, far); //視点の設定------------------------------ gluLookAt( ViewPointX, ViewPointY, ViewPointZ, // 視点の位置x,y,z; 0.0, 0.0, ViewPointZ, // 視界の中心位置の参照点座標x,y,z 0.0, 0.0, 1.0 ) ; //視界の上方向のベクトルx,y,z //---------------------------------------- //モデルビュー変換行列の設定-------------------------- glMatrixMode(GL_MODELVIEW);//行列モードの設定(GL_PROJECTION 透視変換行列の設定、GL_MODELVIEW:モデルビュー変換行列) glLoadIdentity();//行列の初期化 glViewport(0, 0, WindowWidth, WindowHeight); //---------------------------------------------- glEnd(); glPopMatrix(); Ground();//地面描画 glutSwapBuffers(); //glutInitDisplayMode(GLUT_DOUBLE)でダブルバッファリングを利用可 } //---------------------------------------------------- // アイドル時に呼び出される関数 //---------------------------------------------------- void Idle(){ glutPostRedisplay(); //glutDisplayFunc()を1回実行する } //---------------------------------------------------- // 地面の描画(格子) //---------------------------------------------------- void Ground(void){ double ground_max_x = 500.0;//x方向広さ double ground_max_y = 500.0;//y方向広さ glColor3d(0.5, 0.5, 1.0); // 大地の色 glBegin(GL_LINES); for(double ly = -ground_max_y ;ly = ground_max_y; ly+=10.0){ glVertex3d(-ground_max_x, ly,0); glVertex3d(ground_max_x, ly,0); } for(double lx = -ground_max_x ;lx = ground_max_x; lx+=10.0){ glVertex3d(lx, ground_max_y,0); glVertex3d(lx, -ground_max_y,0); } glEnd(); } 下のようなウィンドウが実行されたでしょうか? 真っ白なウィンドウを表示するだけなら↓のソースで可能です。 +←表示するにはこちらをクリック #include ‹GL/glut.h› int WindowPositionX = 100; //生成するウィンドウ位置のX座標 int WindowPositionY = 100; //生成するウィンドウ位置のY座標 int WindowWidth = 512; //生成するウィンドウの幅 int WindowHeight = 512; //生成するウィンドウの高さ char WindowTitle[] = 世界の始まり ;//ウィンドウのタイトル //---------------------------------------------------- // 関数プロトタイプ(後に呼び出す関数名と引数の宣言) //---------------------------------------------------- void Initialize(void); void Display(void); //---------------------------------------------------- // メイン関数 //---------------------------------------------------- int main(int argc, char *argv[]){ glutInit(&argc, argv);//環境の初期化 glutInitWindowPosition(WindowPositionX, WindowPositionY);//ウィンドウの位置の指定 glutInitWindowSize(WindowWidth, WindowHeight); //ウィンドウサイズの指定 glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);//ディスプレイモードの指定 glutCreateWindow(WindowTitle); //ウィンドウの作成 glutDisplayFunc(Display); //描画時に呼び出される関数を指定する(関数名:Display) Initialize(); //初期設定の関数を呼び出す glutMainLoop(); return 0; } //---------------------------------------------------- // 初期設定の関数 //---------------------------------------------------- void Initialize(void){ glClearColor(1.0, 1.0, 1.0, 1.0); //背景色 glEnable(GL_DEPTH_TEST);//デプスバッファを使用:glutInitDisplayMode() で GLUT_DEPTH を指定する } //---------------------------------------------------- // 描画の関数 //---------------------------------------------------- void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //バッファの消去 glutSwapBuffers(); //glutInitDisplayMode(GLUT_DOUBLE)でダブルバッファリングを利用可 } ここでのキーワードは以下の通りです。 プログラムの全体的流れの把握 視点という概念 地面の描写 地面の上に立方体を表示して、視点を変えてみよう(2010/5/5 編集中) 地面だけでは味気ないですね。さて、実際に物体、ここでは立方体を描写しましょう。 ソースはこちらです。 下のようなウィンドウが実行されたでしょうか? ここでのキーワードは以下の通りです。 視点の移動 オブジェクトの描画 マウスドラッグで立方体をグリグリ回してみよう(2010/5/5 編集中) キーボード入力をしてみよう(2010/5/5 編集中) ここではキーボードからの入力によって視点(ViewPoint)を変えてみましょう。 下記のソースを実行すると下図のようなウィンドウが開きます。 キー操作は「a,s,d,wがそれぞれ左、下、右、上」「qが終了」となっています。 +←ソースを表示するにはこちらをクリック #include ‹math.h› #include ‹fstream› #include ‹sstream› #include ‹iostream› #include ‹direct.h› #include ‹GL/glut.h› double PI = acos(-1.0); int WindowPositionX = 400; //生成するウィンドウ位置のX座標 int WindowPositionY = 200; //生成するウィンドウ位置のY座標 int WindowWidth = 640; //生成するウィンドウの幅 int WindowHeight = 480; //生成するウィンドウの高さ char WindowTitle[] = ロボット視点ぐりぐり ; //ウィンドウのタイトル double ViewPointX = 0.0; double ViewPointY = -200.0; double ViewPointZ = 50.0; int tn = 0,zn=50 ; double t = 0; double dt = 0.1; double omega = 2.0 * PI / 20.0; //---------------------------------------------------- // 立方体の定義 //---------------------------------------------------- GLdouble vertex[][3] = { { -10.0, -10.0, 0.0 }, { 10.0, -10.0, 0.0 }, { 10.0, 10.0, 0.0 }, { -10.0, 10.0, 0.0 }, { -10.0, -10.0, 20.0 }, { 10.0, -10.0, 20.0 }, { 10.0, 10.0, 20.0 }, { -10.0, 10.0, 20.0 } },; int face[][4] = {//面の定義 { 0, 1, 2, 3 }, { 1, 5, 6, 2 }, { 5, 4, 7, 6 }, { 4, 0, 3, 7 }, { 4, 5, 1, 0 }, { 3, 2, 6, 7 }, } GLdouble normal[][3] = {//面の法線ベクトル { 0.0, 0.0,-1.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 }, {-1.0, 0.0, 0.0 }, { 0.0,-1.0, 0.0 }, { 0.0, 1.0, 0.0 }, } //---------------------------------------------------- // 物質質感の定義 //---------------------------------------------------- struct MaterialStruct { GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; GLfloat shininess; } //jade(翡翠) MaterialStruct ms_jade = { {0.135, 0.2225, 0.1575, 1.0}, {0.54, 0.89, 0.63, 1.0}, {0.316228, 0.316228, 0.316228, 1.0}, 12.8} //---------------------------------------------------- // 色の定義の定義 //---------------------------------------------------- GLfloat green[] = { 0.2, 0.8, 0.2, 1.0 }//緑色 GLfloat shininess = 30.0;//光沢の強さ //----------------------------------------- //---------------------------------------------------- // 関数プロトタイプ(後に呼び出す関数名と引数の宣言) //---------------------------------------------------- void Initialize(void); void Display(void); void Idle(); void Ground(void); //大地の描画 void Keyboard(unsigned char key, int x, int y); //---------------------------------------------------- // メイン関数 //---------------------------------------------------- int main(int argc, char *argv[]){ glutInit(&argc, argv);//環境の初期化 glutInitWindowPosition(WindowPositionX, WindowPositionY);//ウィンドウの位置の指定 glutInitWindowSize(WindowWidth, WindowHeight); //ウィンドウサイズの指定 glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);//ディスプレイモードの指定 glutCreateWindow(WindowTitle); //ウィンドウの作成 glutDisplayFunc(Display); //描画時に呼び出される関数を指定する(関数名:Display) glutKeyboardFunc(Keyboard);//キーボード入力時に呼び出される関数を指定する(関数名:Keyboard) glutIdleFunc(Idle); //プログラムアイドル状態時に呼び出される関数 Initialize(); //初期設定の関数を呼び出す glutMainLoop(); return 0; } //---------------------------------------------------- // 初期設定の関数 //---------------------------------------------------- void Initialize(void){ glClearColor(0.6, 0.6, 0.9, 1.0); //背景色 glEnable(GL_DEPTH_TEST);//デプスバッファを使用:glutInitDisplayMode() で GLUT_DEPTH を指定する //光源の設定-------------------------------------- GLfloat light_position0[] = { -50.0, -50.0, 20.0, 1.0 }//光源0の座標 glLightfv(GL_LIGHT0, GL_POSITION, light_position0); //光源0を } //---------------------------------------------------- // 描画の関数 //---------------------------------------------------- void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //バッファの消去 t = dt * tn;//tnは後ほどインクリメントされる ViewPointX = -100.0 * cos( omega * t);//立方体の周りをぐるぐる視点が回転する ViewPointY = -100.0 * sin( omega * t);//Z軸方向から見ると回転運動 ViewPointZ = 50+zn; //Z軸方向から見ると回転運動 //透視変換行列の設定------------------------------ glMatrixMode(GL_PROJECTION);//行列モードの設定(GL_PROJECTION 透視変換行列の設定、GL_MODELVIEW:モデルビュー変換行列) glLoadIdentity();//行列の初期化 gluPerspective(30.0, (double)WindowWidth/(double)WindowHeight, 0.1, 1000.0); //透視投影法の視体積gluPerspactive(th, w/h, near, far); //視点の設定------------------------------ gluLookAt( ViewPointX, ViewPointY, ViewPointZ, // 視点の位置x,y,z; 0.0, 0.0, 0.0, // 視界方向 0.0, 0.0, 1.0 ) ; //重力方向、要するに「上・空」はどっち? //---------------------------------------- //モデルビュー変換行列の設定-------------------------- glMatrixMode(GL_MODELVIEW);//行列モードの設定(GL_PROJECTION 透視変換行列の設定、GL_MODELVIEW:モデルビュー変換行列) glLoadIdentity();//行列の初期化 glViewport(0, 0, WindowWidth, WindowHeight); //---------------------------------------------- //陰影ON----------------------------- glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);//光源0を利用 //----------------------------------- //立方体 glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, ms_jade.ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, ms_jade.diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, ms_jade.specular); glMaterialfv(GL_FRONT, GL_SHININESS, &ms_jade.shininess); glTranslated(0.0, 0.0, 0.0);//平行移動値の設定 glBegin(GL_QUADS); for (int j = 0; j 6; ++j) { glNormal3dv(normal[j]); //法線ベクトルの指定 for (int i = 0; i 4; ++i) { glVertex3dv(vertex[face[j][i]]); } } glEnd(); glPopMatrix(); //陰影OFF----------------------------- glDisable(GL_LIGHTING); //----------------------------------- Ground(); glutSwapBuffers(); //glutInitDisplayMode(GLUT_DOUBLE)でダブルバッファリングを利用可 } //---------------------------------------------------- // アイドル時に呼び出される関数 //---------------------------------------------------- void Idle(){ glutPostRedisplay(); //glutDisplayFunc()を1回実行する } //---------------------------------------------------- // 地面の描画 //---------------------------------------------------- void Ground(void){ double ground_max_x = 500.0; double ground_max_y = 500.0; glColor3d(0.8, 0.8, 0.8); // 大地の色 glBegin(GL_LINES); for(double ly = -ground_max_y ;ly = ground_max_y; ly+=10.0){ glVertex3d(-ground_max_x, ly,0); glVertex3d(ground_max_x, ly,0); } for(double lx = -ground_max_x ;lx = ground_max_x; lx+=10.0){ glVertex3d(lx, ground_max_y,0); glVertex3d(lx, -ground_max_y,0); } glEnd(); } //---------------------------------------------------- // キーボード入力時に呼び出される関数 //---------------------------------------------------- void Keyboard(unsigned char key, int x, int y){ switch ( key ) { case a //「a」を押したら反時計回り tn--; break; case d //「d」を押したら時計回り tn++; break; case w //「w」を押したら視点上昇 zn++; break; case s //「s」を押したら視点下降 zn--; break; case q //「q」を押したら終了 exit(0); break; default break; } } 文字の表示をしてみよう(2010/5/5 編集中) ウィンドウ映像をビットマップで紙芝居的に保存しよう(2010/5/5 編集中) ゲームパッド(コントローラ)で入力してみよう(2010/5/5 編集中) 半透明な物体を表現してみよう(2010/5/5 編集中) 動く笑い男を表示してみよう(2010/5/5 編集中)
https://w.atwiki.jp/slab/pages/14.html
開発環境の構築(Windows) 下記サイトを参照。 VisualC++ を使った OpenGL 入門【0.1日目】OpenGL と Visual C++ 2008 Express Edition の準備 まずはVisual Studio 2010をインストールする。(Visual C++ 2010 Express EditionでもOK。Visual C++ 2010 Express Editionは無料。) GLUTのダウンロードサイトの一番上にある「glut-3.7.6-bin.zip (117 KB)」をダウンロードする。 Windows7でVisual Studio 2010を使って開発する場合は、解凍したzipに入っている3つのファイルを以下のように配置する。 ファイル名 設置場所 glut32.dll C \Windows\SysWOW64 glut32.lib C \Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib glut.h C \Program Files (x86)\Microsoft Visual Studio 10.0\VC\include Visual Studio 2010でプロジェクトを作成する際に、プロジェクトの種類を「CLR」にして開発をする。
https://w.atwiki.jp/sevenlives/pages/2256.html
GLUT OpenGL ES GLSL? WebGL OpenCL? シリコングラフィックス?
https://w.atwiki.jp/shiitakeo/pages/25.html
@Mac ヘッダファイルのインクルード Winでは #include GL/glut.h だけど,Macだと #include GLUT/glut.h にする. コンパイルするとき. frameworkを指定してやる.GLUT使うならそれも. $gcc -framework OpenGL -framework GLUT prg.c *